package com.accenture.adf.newcodington.module16.activity.advanced;

import org.junit.Test;

import com.accenture.adf.newcodington.module16.activity.Temperature;
import com.accenture.adf.newcodington.module16.activity.TemperatureConvertor;



import junit.framework.TestCase;
/**
 * Topic : Unit Testing
 * 
 * Description:
 * 
 * The TestTemperatureConvertorActivity class is used test 
 * the workflow conditions of the TemperatureConvertor domain class. 
 * It tests the normal condition and the exception conditions for the class
 * This is the solution file for the activity
 */

public class TestTemperatureConvertorActivity extends TestCase {

	// Local objects of Temparature and TemperatureConvertorSolution classes
	Temperature temperature;
	TemperatureConvertor convertorSolution;

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.009: Initialization is done successfully
	 */
	public void testTemparatureConvertorSolution() {

		temperature = new Temperature();
		convertorSolution = new TemperatureConvertor(temperature);
		assertEquals(
				"Temperature Converter Initiated:  Temperature Data Received",
				convertorSolution.getConversionMessage());
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.010: Pass Temperature Object (no Temperature Object)
	 */
	public void testTemperatureConvertorSolutionTemperature_NoObject() {

		try {
			convertorSolution = new TemperatureConvertor(null);
		} catch (NullPointerException ex) {
			assertEquals("The Temperature Object was not found",
					ex.getMessage());
		}
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.011: Pass Temperature Object (temperature, currUOM
	 * and newUOM are VALID but the same)
	 */
	public void testTemperatureConvertorSolutionTemperature_SameUOM() {

		temperature = new Temperature(32f, 'F', 'F');
		try {
			convertorSolution = new TemperatureConvertor(temperature);
		} catch (ArithmeticException ex) {
			assertEquals(	"No conversion required.  The units of measure are the same.",ex.getMessage());
		}
	}
	@Test
	/**
	 *  TCS.UT.AP331.TC.012: Celsius to Fahrenheit
	 */
	public void testConvertTemperature_Celsius_Fahrenheit() {

		temperature = new Temperature(50.0f, 'C', 'F');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(122f, temperature.getTemperature(), 0.01);
		assertEquals('F', temperature.getCurrUOM());
		assertEquals('C', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.013: Test Celsius to Kelvin
	 */
	public void testConvertTemperature_Celsius_Kelvin() {
		temperature = new Temperature(100.0f, 'C', 'K');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(373.15f, temperature.getTemperature(), 0.01);
		assertEquals('K', temperature.getCurrUOM());
		assertEquals('C', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 *  TCS.UT.AP331.TC.014: Test Fahrenheit to Celsius
	 */
	public void testConvertTemperature_Fahrenheit_Celsius() {
		temperature = new Temperature(212.0f, 'F', 'C');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(100f, temperature.getTemperature(), 0.01);
		assertEquals('C', temperature.getCurrUOM());
		assertEquals('F', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 *  TCS.UT.AP331.TC.015: Test Fahrenheit to Kelvin
	 */
	public void testConvertTemperature_Fahrenheit_Kelvin() {
		temperature = new Temperature(-94.0f, 'F', 'K');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(203.15f, temperature.getTemperature(), 0.01);
		assertEquals('K', temperature.getCurrUOM());
		assertEquals('F', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 *  TCS.UT.AP331.TC.016: Test Kelvin to Celsius
	 */
	public void testConvertTemperature_Kelvin_Celsius() {
		temperature = new Temperature(367.0f, 'K', 'C');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(93.85f, temperature.getTemperature(), 0.01);
		assertEquals('C', temperature.getCurrUOM());
		assertEquals('K', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 *  TCS.UT.AP331.TC.017: Test Kelvin to Fahrenheit
	 */
	public void testConvertTemperature_Kelvin_Fahrenheit() {
		temperature = new Temperature(32.0f, 'K', 'F');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(-402.07f, temperature.getTemperature(), 0.01);
		assertEquals('F', temperature.getCurrUOM());
		assertEquals('K', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.018:Test Fahrenheit to Celsius: Absolute zero check -
	 * adjust Celsius temperature
	 */
	public void testConvertTemperature_Fahrenheit_Celsius_AbsoluteZero() {

		temperature = new Temperature(-459.7f, 'F', 'K');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(0f, temperature.getTemperature(), 0.01);
		assertEquals('K', temperature.getCurrUOM());
		assertEquals('K', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.019:Test Kelvin to Fahrenheit : Absolute zero check -
	 * adjust Fahrenheit temperature
	 */
	public void testConvertTemperature_Kelvin_Fahrenheit_AbsoluteZero() {

		temperature = new Temperature(-0.1f, 'K', 'F');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(0f, temperature.getTemperature(), 0.01);
		assertEquals('K', temperature.getCurrUOM());
		assertEquals('K', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------
	}
	@Test
	/**
	 * TCS.UT.AP331.TC.020:Test Celsius to Kelvin : Absolute zero check -
	 * adjust Kelvin temperature
	 */
	public void testConvertTemperature_Celsius_Kelvin_AbsoluteZero() {

		temperature = new Temperature(-273.16f, 'C', 'K');
		convertorSolution = new TemperatureConvertor();
		convertorSolution.convertTemperature(temperature);
		assertEquals("Conversion Performed", convertorSolution
				.getConversionMessage().substring(1, 21));

		// Test Conversion worked in object
		assertEquals(0f, temperature.getTemperature(), 0.01);
		assertEquals('K', temperature.getCurrUOM());
		assertEquals('K', temperature.getNewUOM());

		// -------***********<<<<<<Test Condition
		// Checked>>>>>>**********---------------

	}

}
